{extend name="public:layout" /}
{block name="title"}商机列表{/block}
{block name="head"}
<link rel="stylesheet" href="/public/home/plugins/dropload/dropload.css">
<style>
    .list-tab{width:100%;position:fixed;top:0;z-index:9;border-bottom:10px solid #fff;}
    .list-box{margin-top:50px;}
</style>
{/block}
{block name="body"}
<div class="app-list">
    <ul class="am-avg-sm-3 list-tab">
        <li class="item"><a href="{:url('home/Index/index',['folder'=>'business','file'=>'list','business_status'=>1])}" class="link {eq name='$Request.param.leads_status' value='1'}active{/eq}">近7日跟进</a></li>
        <li class="item"><a href="{:url('home/Index/index',['folder'=>'business','file'=>'list','business_status'=>2])}" class="link {eq name='$Request.param.leads_status' value='2'}active{/eq}">本周新增</a></li>
        <li class="item"><a href="{:url('home/Index/index',['folder'=>'business','file'=>'list'])}" class="link {empty name='$Request.param.leads_status'}active{/empty}">全部商机</a></li>
    </ul>
    <div class="list-box" id="list-box">
        <ul class="leads-list" id="leads-list">
        </ul>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/html" id="leads-tpl">
    {{ each data as value }}
    <li class="item">
        <a href="{:url('home/Index/index',['folder'=>'business','file'=>'info'])}&leads_id={{ value.leads_id }}" class="link"></a>
        <div class="thumb">
            <span class="surname bg-color1">{{ value.surname }}</span>
        </div>
        <div class="info-box">
            <h2 class="name">{{ value.name }}<span class="sex">{{ value.sex }}</span></h2>
            <span class="mobile">预计成交金额：{{ value.mobile }}</span>
            <p class="info">预计成交日期{{ value.create_time }}
                {{ if value.record_count!='' }}<br>销售阶段：{{ value.last_time }} {{ /if }}</p>
        </div>
        <div class="action-box">
            <a href="tel:{{ value.mobile }}" class="action-link">
                <span class="iconfont icon-iconfontphone"></span>
            </a>
            <a href="{:url('home/Index/index',['folder'=>'business','file'=>'follow'])}&leads_id={{ value.leads_id }}" class="action-link">
                <span class="iconfont icon-add"></span>
            </a>
        </div>
    </li>
    {{ /each }}
</script>
<script src="/public/home/plugins/dropload/dropload.min.js"></script>
<script>
    $(function () {
        dropload();
        setRight();
    });
    // dropload
    function dropload() {
        var data = {
            page: 0,
            leads_status:"{$Request.param.leads_status}",
        };
        var drop = $('#list-box').dropload({
            scrollArea: window,
            domUp : {
                domClass   : 'dropload-up',
                domRefresh : '<div class="dropload-refresh">↓下拉刷新</div>',
                domUpdate  : '<div class="dropload-update">↑释放加载内容</div>',
                domLoad    : '<div class="dropload-load"><span class="loading"></span>加载中...</div>'
            },
            domDown : {
                domClass   : 'dropload-down',
                domRefresh : '<div class="dropload-refresh">↑上拉加载更多</div>',
                domLoad    : '<div class="dropload-load"><span class="loading"></span>加载中</div>',
                domNoData  : '<div class="dropload-noData">内容加载完毕</div>'
            },
            loadUpFn:function (me) {
                data.page = 1;
                $.ajax({
                    url: "{:url('home/Leads/index')}",
                    data: data,
                    success: function(res){
                        console.log(1);
                        console.log(res);
                        var result = '';
                        var html = template('leads-tpl',{data:res.data.data});
                        // 为了测试，延迟1秒加载
                        setTimeout(function(){
                            $('#leads-list').empty().append(html);
                            // 每次数据加载完，必须重置
                            me.resetload();
                            // 解锁loadDownFn里锁定的情况
                            me.unlock();
                            me.noData(false);
                        },1000);
                    },
                    error: function(xhr, type){
                        alert('Ajax error!');
                        // 即使加载出错，也得重置
                        me.resetload();
                    }
                });
            },
            loadDownFn: function (me) {
                data.page++;
                // 拼接HTML
                var result = '';
                $.ajax({
                    url: "{:url('home/Leads/index')}",
                    data: data,
                    success: function (res) {
                        console.log(2);
                        console.log(res);
                        if (data.page >= res.data.last_page) {
                            // 锁定
                            me.lock();
                            // 无数据
                            me.noData();
                        }
                        var html = template('leads-tpl', {data:res.data.data});
                        $('#leads-list').append(html);
                        me.resetload();
                        if(res.data.data.length<4){
                            $('.dropload-noData').remove();
                        }
                    },
                    error: function (xhr, type) {
                        layer.open({
                            content: '加载出错'
                            , skin: 'msg'
                            , time: 2 //2秒后自动关闭
                        });
                        // 锁定
                        me.lock();
                        // 无数据
                        me.noData();
                        me.resetload();
                    }
                });
            }
        });
    }
    function setRight() {
        dd.ready(function () {
            dd.biz.navigation.setRight({
                show: true,//控制按钮显示， true 显示， false 隐藏， 默认true
                control: true,//是否控制点击事件，true 控制，false 不控制， 默认false
                text: '新增线索',//控制显示文本，空字符串表示显示默认文本
                onSuccess : function(result) {
                    location.href="{:url('home/Index/index',['folder'=>'leads','file'=>'add'])}";
                },
                onFail : function(err) {}
            });
        })
    }
</script>
{/block}